using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
using MobileClient.UIProcessService;

namespace MobileClient
{
	/// <summary>
	/// Summary description for ctlAddressEntryNA.
	/// </summary>
	public class ctlAddressEntryNA : Control
	{
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;
		private System.Windows.Forms.TabControl tabControl;
		private System.Windows.Forms.TabPage tabStreet;
		private System.Windows.Forms.Label lblAddress1;
		private System.Windows.Forms.TextBox txtAddress1;
		private System.Windows.Forms.Label lblAddress2;
		private System.Windows.Forms.TextBox txtAddress2;
		private System.Windows.Forms.TabPage tabState;
		private System.Windows.Forms.Label lblState;
		private System.Windows.Forms.ComboBox cbState;
		private System.Windows.Forms.TabPage tabCity;
		private System.Windows.Forms.Label lblCity;
		private System.Windows.Forms.TextBox txtCity;
		private System.Windows.Forms.TabPage tabCountry;
		private System.Windows.Forms.Label lblCountry;
		private System.Windows.Forms.TextBox txtCountry;
		private System.Windows.Forms.TabPage tabPostalCode;
		private System.Windows.Forms.Label lblPostalCode;
		private System.Windows.Forms.TextBox txtPostalCode;
		private System.Windows.Forms.TabPage tabNA;
		private System.Windows.Forms.CheckBox chkNA;
		private AddressEntryNA m_objEntry;
		private int m_nSelected = 0;
		private Microsoft.WindowsCE.Forms.InputPanel pnlSIP;

		public ctlAddressEntryNA()
		{
			// This call is required by the Windows.Forms Form Designer.
			InitializeComponent();

			m_objEntry = null;
			pnlSIP = null;
		}

		public AddressEntryNA Entry
		{
			get { return m_objEntry; }
			set { m_objEntry = value; }
		}

		public Microsoft.WindowsCE.Forms.InputPanel SIPPanel
		{
			get { return pnlSIP; }
			set { pnlSIP = value; }
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if( components != null )
					components.Dispose();
			}
			base.Dispose( disposing );
		}

		#region Component Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify 
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.tabControl = new System.Windows.Forms.TabControl();
			this.tabStreet = new System.Windows.Forms.TabPage();
			this.txtAddress2 = new System.Windows.Forms.TextBox();
			this.lblAddress2 = new System.Windows.Forms.Label();
			this.txtAddress1 = new System.Windows.Forms.TextBox();
			this.lblAddress1 = new System.Windows.Forms.Label();
			this.tabState = new System.Windows.Forms.TabPage();
			this.cbState = new System.Windows.Forms.ComboBox();
			this.lblState = new System.Windows.Forms.Label();
			this.tabCity = new System.Windows.Forms.TabPage();
			this.txtCity = new System.Windows.Forms.TextBox();
			this.lblCity = new System.Windows.Forms.Label();
			this.tabCountry = new System.Windows.Forms.TabPage();
			this.txtCountry = new System.Windows.Forms.TextBox();
			this.lblCountry = new System.Windows.Forms.Label();
			this.tabPostalCode = new System.Windows.Forms.TabPage();
			this.txtPostalCode = new System.Windows.Forms.TextBox();
			this.lblPostalCode = new System.Windows.Forms.Label();
			this.tabNA = new System.Windows.Forms.TabPage();
			this.chkNA = new System.Windows.Forms.CheckBox();
			// 
			// tabControl
			// 
			this.tabControl.Controls.Add(this.tabStreet);
			this.tabControl.Controls.Add(this.tabCity);
			this.tabControl.Controls.Add(this.tabState);
			this.tabControl.Controls.Add(this.tabCountry);
			this.tabControl.Controls.Add(this.tabPostalCode);
			this.tabControl.Controls.Add(this.tabNA);
			this.tabControl.Location = new System.Drawing.Point(3, 6);
			this.tabControl.SelectedIndex = 0;
			this.tabControl.Size = new System.Drawing.Size(230, 140);
			this.tabControl.SelectedIndexChanged += new EventHandler(tabControl_SelectedIndexChanged);
			// 
			// tabStreet
			// 
			this.tabStreet.Controls.Add(this.txtAddress2);
			this.tabStreet.Controls.Add(this.lblAddress2);
			this.tabStreet.Controls.Add(this.txtAddress1);
			this.tabStreet.Controls.Add(this.lblAddress1);
			this.tabStreet.Location = new System.Drawing.Point(4, 22);
			this.tabStreet.Size = new System.Drawing.Size(222, 114);
			this.tabStreet.Text = "Street";
			// 
			// txtAddress2
			// 
			this.txtAddress2.Location = new System.Drawing.Point(4, 88);
			this.txtAddress2.Size = new System.Drawing.Size(212, 20);
			this.txtAddress2.Text = "";
			this.txtAddress2.GotFocus +=new EventHandler(txtAddress2_GotFocus);
			// 
			// lblAddress2
			// 
			this.lblAddress2.Location = new System.Drawing.Point(4, 62);
			this.lblAddress2.Size = new System.Drawing.Size(64, 20);
			this.lblAddress2.Text = "Address 2:";
			// 
			// txtAddress1
			// 
			this.txtAddress1.Location = new System.Drawing.Point(4, 34);
			this.txtAddress1.Size = new System.Drawing.Size(212, 20);
			this.txtAddress1.Text = "";
			this.txtAddress1.GotFocus += new EventHandler(txtAddress1_GotFocus);
			// 
			// lblAddress1
			// 
			this.lblAddress1.Location = new System.Drawing.Point(4, 6);
			this.lblAddress1.Size = new System.Drawing.Size(64, 20);
			this.lblAddress1.Text = "Address 1:";
			// 
			// tabState
			// 
			this.tabState.Controls.Add(this.cbState);
			this.tabState.Controls.Add(this.lblState);
			this.tabState.Location = new System.Drawing.Point(4, 22);
			this.tabState.Size = new System.Drawing.Size(222, 114);
			this.tabState.Text = "State";
			this.tabState.Visible = false;
			// 
			// cbState
			// 
			this.cbState.Items.Add("AA");
			this.cbState.Items.Add("AB");
			this.cbState.Items.Add("AE");
			this.cbState.Items.Add("AK");
			this.cbState.Items.Add("AL");
			this.cbState.Items.Add("AP");
			this.cbState.Items.Add("AR");
			this.cbState.Items.Add("AZ");
			this.cbState.Items.Add("BC");
			this.cbState.Items.Add("CA");
			this.cbState.Items.Add("CO");
			this.cbState.Items.Add("CT");
			this.cbState.Items.Add("DC");
			this.cbState.Items.Add("DE");
			this.cbState.Items.Add("FL");
			this.cbState.Items.Add("GA");
			this.cbState.Items.Add("GU");
			this.cbState.Items.Add("HI");
			this.cbState.Items.Add("IA");
			this.cbState.Items.Add("ID");
			this.cbState.Items.Add("IL");
			this.cbState.Items.Add("IN");
			this.cbState.Items.Add("KS");
			this.cbState.Items.Add("KY");
			this.cbState.Items.Add("LA");
			this.cbState.Items.Add("MA");
			this.cbState.Items.Add("MD");
			this.cbState.Items.Add("ME");
			this.cbState.Items.Add("MI");
			this.cbState.Items.Add("MN");
			this.cbState.Items.Add("MO");
			this.cbState.Items.Add("MP");
			this.cbState.Items.Add("MS");
			this.cbState.Items.Add("MT");
			this.cbState.Items.Add("NB");
			this.cbState.Items.Add("NC");
			this.cbState.Items.Add("ND");
			this.cbState.Items.Add("NE");
			this.cbState.Items.Add("NFD");
			this.cbState.Items.Add("NH");
			this.cbState.Items.Add("NJ");
			this.cbState.Items.Add("NM");
			this.cbState.Items.Add("NS");
			this.cbState.Items.Add("NV");
			this.cbState.Items.Add("NWT");
			this.cbState.Items.Add("NY");
			this.cbState.Items.Add("OH");
			this.cbState.Items.Add("OK");
			this.cbState.Items.Add("ON");
			this.cbState.Items.Add("OR");
			this.cbState.Items.Add("PA");
			this.cbState.Items.Add("PEI");
			this.cbState.Items.Add("PR");
			this.cbState.Items.Add("QU");
			this.cbState.Items.Add("RI");
			this.cbState.Items.Add("SA");
			this.cbState.Items.Add("SC");
			this.cbState.Items.Add("SD");
			this.cbState.Items.Add("TN");
			this.cbState.Items.Add("TX");
			this.cbState.Items.Add("UT");
			this.cbState.Items.Add("VA");
			this.cbState.Items.Add("VI");
			this.cbState.Items.Add("VT");
			this.cbState.Items.Add("WA");
			this.cbState.Items.Add("WI");
			this.cbState.Items.Add("WV");
			this.cbState.Items.Add("WY");
			this.cbState.Items.Add("YU");
			this.cbState.Location = new System.Drawing.Point(4, 61);
			this.cbState.Size = new System.Drawing.Size(212, 21);
			// 
			// lblState
			// 
			this.lblState.Location = new System.Drawing.Point(4, 33);
			this.lblState.Size = new System.Drawing.Size(40, 20);
			this.lblState.Text = "State:";
			// 
			// tabCity
			// 
			this.tabCity.Controls.Add(this.txtCity);
			this.tabCity.Controls.Add(this.lblCity);
			this.tabCity.Location = new System.Drawing.Point(4, 22);
			this.tabCity.Size = new System.Drawing.Size(222, 114);
			this.tabCity.Text = "City";
			this.tabCity.Visible = false;
			// 
			// txtCity
			// 
			this.txtCity.Location = new System.Drawing.Point(4, 61);
			this.txtCity.Size = new System.Drawing.Size(212, 20);
			this.txtCity.Text = "";
			this.txtCity.GotFocus += new EventHandler(txtCity_GotFocus);
			// 
			// lblCity
			// 
			this.lblCity.Location = new System.Drawing.Point(4, 33);
			this.lblCity.Size = new System.Drawing.Size(32, 20);
			this.lblCity.Text = "City:";
			// 
			// tabCountry
			// 
			this.tabCountry.Controls.Add(this.txtCountry);
			this.tabCountry.Controls.Add(this.lblCountry);
			this.tabCountry.Location = new System.Drawing.Point(4, 22);
			this.tabCountry.Size = new System.Drawing.Size(222, 114);
			this.tabCountry.Text = "Counrty";
			this.tabCountry.Visible = false;
			// 
			// txtCountry
			// 
			this.txtCountry.Location = new System.Drawing.Point(4, 61);
			this.txtCountry.Size = new System.Drawing.Size(212, 20);
			this.txtCountry.Text = "";
			this.txtCountry.GotFocus += new EventHandler(txtCountry_GotFocus);
			// 
			// lblCountry
			// 
			this.lblCountry.Location = new System.Drawing.Point(4, 33);
			this.lblCountry.Size = new System.Drawing.Size(52, 20);
			this.lblCountry.Text = "Country:";
			// 
			// tabPostalCode
			// 
			this.tabPostalCode.Controls.Add(this.txtPostalCode);
			this.tabPostalCode.Controls.Add(this.lblPostalCode);
			this.tabPostalCode.Location = new System.Drawing.Point(4, 22);
			this.tabPostalCode.Size = new System.Drawing.Size(222, 114);
			this.tabPostalCode.Text = "Postal Code";
			this.tabPostalCode.Visible = false;
			// 
			// txtPostalCode
			// 
			this.txtPostalCode.Location = new System.Drawing.Point(4, 61);
			this.txtPostalCode.Size = new System.Drawing.Size(212, 20);
			this.txtPostalCode.Text = "";
			this.txtPostalCode.GotFocus += new EventHandler(txtPostalCode_GotFocus);
			// 
			// lblPostalCode
			// 
			this.lblPostalCode.Location = new System.Drawing.Point(4, 33);
			this.lblPostalCode.Size = new System.Drawing.Size(76, 20);
			this.lblPostalCode.Text = "Postal Code:";
			// 
			// tabNA
			// 
			this.tabNA.Controls.Add(this.chkNA);
			this.tabNA.Location = new System.Drawing.Point(4, 22);
			this.tabNA.Size = new System.Drawing.Size(222, 114);
			this.tabNA.Text = "N/A";
			this.tabNA.Visible = false;
			// 
			// chkNA
			// 
			this.chkNA.Location = new System.Drawing.Point(66, 47);
			this.chkNA.Text = "Not Applicable";
			// 
			// ctlAddressEntryNA
			// 
			this.Controls.Add(this.tabControl);
			this.Size = new System.Drawing.Size(236, 152);
		}
		#endregion

		public void LoadSettings()
		{
			tabControl.SelectedIndex = 0;

			if(m_objEntry != null)
			{
                if (!String.IsNullOrEmpty(m_objEntry.Address1))
                {
                    txtAddress1.Text = m_objEntry.Address1;
                }
                else
                {
                    txtAddress1.Text = "";
                }

                if (!String.IsNullOrEmpty(m_objEntry.Address2))
                {
				    txtAddress2.Text = m_objEntry.Address2;
                }
                else
                {
                    txtAddress2.Text = "";
                }

                if (!String.IsNullOrEmpty(m_objEntry.City))
                {
				    txtCity.Text = m_objEntry.City;
                }
                else
                {
                    txtCity.Text = "";
                }

                if (!String.IsNullOrEmpty(m_objEntry.State))
                {
				    cbState.Text = m_objEntry.State;
                }
                else
                {
                    cbState.Text = "";
                }

                if (!String.IsNullOrEmpty(m_objEntry.CountryCode))
                {
				    txtCountry.Text = m_objEntry.CountryCode;
                }
                else
                {
                    txtCountry.Text = "";
                }

                if (!String.IsNullOrEmpty(m_objEntry.PostalCode))
                {
				    txtPostalCode.Text = m_objEntry.PostalCode;
                }
                else
                {
                    txtPostalCode.Text = "";
                }

				chkNA.Checked = m_objEntry.NotApplicable;
			}
		}

		public void SaveSettings()
		{
			if(m_objEntry != null)
			{
				m_objEntry.Address1 = txtAddress1.Text;
				m_objEntry.Address2 = txtAddress2.Text;
				m_objEntry.City = txtCity.Text;
				m_objEntry.State = cbState.Text;
				m_objEntry.CountryCode = txtCountry.Text;
				m_objEntry.PostalCode = txtPostalCode.Text;
				m_objEntry.NotApplicable = chkNA.Checked;
			}
		}

		private void tabControl_SelectedIndexChanged(object sender, EventArgs e)
		{
			int nIndex = tabControl.SelectedIndex;
			tabControl.TabPages[m_nSelected].Visible = false;			
			tabControl.TabPages[nIndex].Visible = true;
			m_nSelected = nIndex;
		}

		private void txtAddress2_GotFocus(object sender, EventArgs e)
		{
			pnlSIP.Enabled = true;
		}

		private void txtAddress1_GotFocus(object sender, EventArgs e)
		{
			pnlSIP.Enabled = true;
		}

		private void txtCity_GotFocus(object sender, EventArgs e)
		{
			pnlSIP.Enabled = true;
		}

		private void txtCountry_GotFocus(object sender, EventArgs e)
		{
			pnlSIP.Enabled = true;
		}

		private void txtPostalCode_GotFocus(object sender, EventArgs e)
		{
			pnlSIP.Enabled = true;
		}
	}
}
